/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

/*!
  \file interface.h
	\brief 

  \author Jack Elston
    $Date: 2006/10/25 13:34:45 $
*/

#ifndef __INTERFACE_H
#define __INTERFACE_H

#include <unistd.h>
#include <signal.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>

#include "String.h"
#include "type_defs.h"
#include "threadedPipe.h"

  /*<-------Defines--------->*/
    #define MAX_CAPABILITIES 8
  /*<------End Defines------>*/

/************************************************************\
|                        Interface                           |
\************************************************************/
/*!
  \class Interface
  \brief 
 */
class Interface
{
	typedef struct {
		TimeStamp tx_ts;
		uint8_t   seq_no;
		uint8_t   try_count;
	} PacketDelivery;

	private:
		in_addr  my_subnet;
		uint16_t my_port;
		String   name;
		bool     has_external_if;
		bool     is_gateway;
		bool     can_command;
		CapabilitiesManager my_systems;

		ThreadedPipe * comm[2];
		ThreadedPipe * tran[2];
		ThreadedPipe * comp;

	public:
		enum InputType {	
			TX=0,
			RX 	
		};

		Interface(String a_name);
		~Interface() {};

		void setCommBlock(ThreadedPipe * block);
		void setTranBlock(ThreadedPipe * block);
		void setCompBlock(ThreadedPipe * block);

		/*ThreadedPipe * commBlock() {return comm;};
		  ThreadedPipe * tranBlock() {return tran;};
		  ThreadedPipe * compBlock() {return comp;};*/

		String  getName() {return name;};

		void    setPort(int16_t port) {my_port = port;};
		int16_t getPort() {return my_port;};

		in_addr getSubnet() {return my_subnet;};
		void    setSubnet(in_addr_t address)
		            {my_subnet.s_addr = address;}

		void    registerCapabilities(ShmStruct * shm);
		void    addCapability(SystemCharacter_t * system)
		            {my_systems.add(system);}

		void setExternalIF(bool val=true) {has_external_if = val;}
		bool hasExternalIF() { return has_external_if;}
		void setGateway(bool val=true) {is_gateway = val;}
		bool hasGateway() { return is_gateway;}
		void setCanCommand(bool val=true) { can_command = val; }
		bool canCommand() { return can_command; }

		void start(ShmStruct * shm);
		void stop();

		String getFifo(InputType type);
};

#endif //define
